'''
Created on Jul 21, 2009

@author: xin
@author: Mikael Rousson
'''
import numpy
from scipy import ndimage

def build_lpyr(im, ht, blur_filt, interp_filt):
    """ Constructs a Laplacian pyramid on matrix im.
    
    @param ht          Number of pyramid levels to build.
    @param blur_filt   A string naming a standard filter
    @param interp_filt Specifies the "expansion filter"
    
    @return Returns a vector containing the N pyramid sub-bands, ordered from 
    fine to coarse. "indices" is an Nx2 matrix containing the sizes of each 
    sub-band. This is compatible with the MatLab Wavelet toolbox.
    """
    A = im.copy()
    pyramid = []
    nbScales = 4
    indices = []
    
    tmp = A
    for i in range(nbScales):        
        Ag = ndimage.gaussian_filter(tmp, sigma=2.0)        
        pyramid.append( (-Ag + tmp).ravel() )
        tmp = ndimage.interpolation.zoom(Ag, 0.5)
        indices.append(Ag.shape)

    return numpy.hstack(pyramid), indices
    